<?php
class EncoderFactory {
	private static $instance;
	private $encoderList;
	
	private function __construct() {
	}
	
	static public function getInstance() {
		if (!isset(self::$instance)) {
			$c = __CLASS__;
			self::$instance = new $c();
		}
		
		return self::$instance;	
	}

	// Prevent users to clone the instance
	public function __clone() {
		trigger_error('Clone is not allowed.', E_USER_ERROR);
	}
	
	public function register($format_id, BaseEncoder $encoder) {
		if (isset($this->encoderList[$format_id])) {
			trigger_error("Format {$format_id} is already registered. " . var_export($this->encoderList[$format_id], 1));
		}
		$this->encoderList[$format_id] = $encoder;
	}

	public function getEncoder($format_id) {
		if (isset($this->encoderList[$format_id])) {
			return $this->encoderList[$format_id];
		}
		
		return FALSE;
	}
}
?>
